package controller;

import entity.Cat;
import entity.Shop;
import service.CatService;
import service.ShopService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/shop")
public class ShopController extends BaseServlet {
    CatService catService=new CatService();
    ShopService shopService=new ShopService();

    public void getShop(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 根据品种猫id获取猫的信息
        String id=request.getParameter("id");

        String sql2="select * from cat where id=?";
        Cat cat=catService.getCatById(sql2,id);
        request.setAttribute("cat",cat);
        System.out.println(cat);

        String sql="select * from shop";
        List<Shop> shopList=shopService.getShop(sql);
        // 将查询数据传输到前端展示
        request.setAttribute("shopList",shopList);
        request.getRequestDispatcher("view/shop.jsp").forward(request,response);
    }
}
